package design.create.abstract_factory;

/**
 * 使用反射改进抽象工厂模式
 *
 * @author zxs
 * @since 2020/05/27
 */
public class DefaultFactory implements IFactory  {

    private static final String path = "design.create.abstract_factory";

    private String productType;

    public DefaultFactory(String productType) {
        this.productType = productType;
    }

    public IUser createUser() throws Exception {
        return (IUser) Class.forName(path+"."+productType+".User").getDeclaredConstructor().newInstance();
    }

    public IDepartment createDepartment() throws Exception {
        return (IDepartment) Class.forName(path+"."+productType+".Department").getDeclaredConstructor().newInstance();
    }


}
